package com.suo.notepad.controller;


import com.suo.notepad.pojo.Values;
import com.suo.notepad.service.impl.ValuesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
public class ValuesController {

    @Autowired
    ValuesServiceImpl valuesService;

    @GetMapping("/get-all")
    public List<Values> getAll() {
        return valuesService.list();
    }

    @GetMapping("/get-one")
    public Values getOne(Integer id) {
        return valuesService.getById(id);
    }

    @PostMapping("/remove-one")
    public void removeOne(Integer id) {
        valuesService.removeById(id);
    }

    @PostMapping("/save-one")
    public void saveOne(Values values) {
        values.setTime(LocalDateTime.now());
        valuesService.save(values);
    }

    @PutMapping("/modify-one")
    public void modifyOne(Values values) {
        valuesService.updateById(values);
    }

}
